package com.lsl.endworkvol.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lsl.endworkvol.dao.AdminMapper;
import com.lsl.endworkvol.entity.Admin;
import com.lsl.endworkvol.service.AdminService;
import com.lsl.endworkvol.service.func.IUserBuilder;

@Service
public class AdminServiceImpl implements AdminService{

    @Autowired
    private AdminMapper adminMapper;

    @Override
    public boolean addUser(IUserBuilder builder) {
        return adminMapper.insertAdmin((Admin)builder.build()) > 0;
    }

    @Override
    public boolean editUser(IUserBuilder builder) {
        Admin admin = (Admin)builder.build();
        if (admin.getPassword().isEmpty()) {
            admin.setPassword(getUser(admin.getId()).getPassword());
        }
        return adminMapper.updateAdmin(admin) > 0;
    }

    @Override
    public Admin getUser(Integer id) {
        return adminMapper.selectAdmin(id);
    }

    @Override
    public boolean deleteUser(Integer id) {
        return adminMapper.deleteAdmin(id) > 0;
    }

    @Override
    public boolean loginCheck(String id, String password) {
        Admin admin = getUser(Integer.parseInt(id));
        return admin != null && admin.getPassword().equals(password);
    }

    /*
     * 此方法无意义，因为不需要批量查询系统管理员
     */
    @Override
    public List<Admin> getUsers() {
        return null;
    }

    /*
     * 此方法无意义，因为不需要批量查询系统管理员
     */
    @Override
    public List<Admin> getUsers(IUserBuilder builder) {
        return null;
    }
    
}
